package cn.aiyuan.controller;

import cn.aiyuan.listen.TestListen;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wangyuan
 * @date 2021/10/15
 */
@RestController
@RequestMapping("/msg")
@Slf4j
public class KafkaMsgController {

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping("/send/{msg}")
    public String test(@PathVariable("msg") String msg) {
        kafkaTemplate.send(TestListen.TOPIC_MSG, msg);
        log.info(msg);
        return msg;
    }


}
